package protocol.transactions;

import protocol.XoneProtocol;
import protocol.XoneServiceCode;
import protocol.meta.User;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.netease.http.THttpRequest;


public class GetUserDetailTransaction extends XoneBaseTransaction {

    private String mUserId;
    public GetUserDetailTransaction(String userId) {
        super(TRANSACTION_TYPE_GET_USER_DETAIL);
        mUserId = userId;
    }

    @Override
    public void onTransact() {
        THttpRequest request = XoneProtocol.getInstance().createGetUserDetailRequest(mUserId);
        sendRequest(request);
    }

    @Override
    protected void onXoneTransactionSuccess(int code, Object obj) {
        if (obj != null && obj instanceof JsonElement) {
            JsonElement jsonSource = ((JsonElement)obj).getAsJsonObject().get("user");
            Gson gson = new Gson();
            User user = gson.fromJson(jsonSource, User.class);
            notifyMessage(XoneServiceCode.TRANSACTION_SUCCESS, user);
        } else {
            // TODO
            // notifyError(errCode, arg3)
        }
    }

}
